﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Me.Prettyprint.Cassandra.Utils;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// DynamicCompositeSerializer assumes the Composite will handle the
    /// conversion between big/little endian encoding.
    /// </summary>
    public class DynamicCompositeSerializer: AbstractSerializer<Me.Prettyprint.Hector.Api.Beans.DynamicComposite>
    {
        public static DynamicCompositeSerializer Instance = new DynamicCompositeSerializer();

        public DynamicCompositeSerializer()
        {
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.DYNAMICCOMPOSITETYPE;
        }
        public override ComparatorType ComparatorType
        {
            get
            {
                return ComparatorType.DYNAMICCOMPOSITETYPE;
            }
        }
        public override byte[] ToBytes(Me.Prettyprint.Hector.Api.Beans.DynamicComposite obj)
        {
            return obj.Serialize().GetBuffer();
        }
        public override Utils.ByteBuffer ToByteBuffer(DynamicComposite obj)
        {
            return new ByteBuffer(ToBytes(obj));
        }
        public override Me.Prettyprint.Hector.Api.Beans.DynamicComposite FromBytes(byte[] bytes)
        {
            DynamicComposite dynamic = new DynamicComposite();
            dynamic.Deserialize(new Utils.ByteBuffer(bytes));
            return dynamic;
        }
        public override Me.Prettyprint.Hector.Api.Beans.DynamicComposite FromByteBuffer(ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
